home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWInsCmd.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  4.4 KB  |  205 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWInsCmd.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWINSCMD_H
  13. #include "FWInsCmd.h"
  14. #endif
  15.  
  16. #ifndef FWPART_H
  17. #include "FWPart.h"
  18. #endif
  19.  
  20. #ifndef FWINTER_H
  21. #include "FWInter.h"
  22. #endif
  23.  
  24. #ifndef FWFRMING_H
  25. #include "FWFrming.h"
  26. #endif
  27.  
  28. #ifndef FWSELECT_H
  29. #include "FWSelect.h"
  30. #endif
  31.  
  32. #ifndef FWLINK_H
  33. #include "FWLink.h"
  34. #endif
  35.  
  36. #ifndef FWLNKMGR_H
  37. #include "FWLnkMgr.h"
  38. #endif
  39.  
  40. #ifndef FWEMBUTL_H
  41. #include "FWEmbUtl.h"
  42. #endif
  43.  
  44. #ifndef FWPRESEN_H
  45. #include "FWPresen.h"
  46. #endif
  47.  
  48. // ----- OS Layer -----
  49.  
  50. #ifndef FWBARRAY_H
  51. #include "FWBArray.h"
  52. #endif
  53.  
  54. #ifndef SLODFSTR_K
  55. #include "SLODFStr.k"
  56. #endif
  57.  
  58. #ifndef SLODFSTR_H
  59. #include "SLODFStr.h"
  60. #endif
  61.  
  62. // ----- OpenDoc Includes -----
  63.  
  64. #ifndef SOM_Module_OpenDoc_Commands_defined
  65. #include <CmdDefs.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODSession_xh
  69. #include <ODSessn.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODClipboard_xh
  73. #include <Clipbd.xh>
  74. #endif
  75.  
  76. #ifndef SOM_Module_OpenDoc_StdProps_defined
  77. #include <StdProps.xh>
  78. #endif
  79.  
  80. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  81. #include <StdTypes.xh>
  82. #endif
  83.  
  84. #ifndef SOM_ODStorageUnit_xh
  85. #include <StorageU.xh>
  86. #endif
  87.  
  88. #ifndef SOM_ODLinkSpec_xh
  89. #include <LinkSpec.xh>
  90. #endif
  91.  
  92. //========================================================================================
  93. //    Runtime Info
  94. //========================================================================================
  95.  
  96. #ifdef FW_BUILD_MAC
  97. #pragma segment odfcommands
  98. #endif
  99.  
  100. FW_DEFINE_AUTO(FW_CInsertCommand)
  101.  
  102. //====================================================================
  103. // FW_CInsertCommand class
  104. //====================================================================
  105.  
  106. //--------------------------------------------------------------------
  107. // FW_CInsertCommand constructor
  108. //--------------------------------------------------------------------
  109.  
  110. FW_CInsertCommand::FW_CInsertCommand(Environment* ev,
  111.                                     FW_CEmbeddingFrame* frame,
  112.                                     const FW_PFileSpecification& fileSpec,
  113.                                     FW_Boolean canUndo) :
  114.     FW_CCommand(ev, kODCommandInsert, frame, canUndo),
  115.     fFileSpec(fileSpec),
  116.     fEmbeddingFrame(frame)
  117. {
  118.     if (GetCanUndo(ev))
  119.     {
  120.         FW_CString undoString;
  121.         FW_CString redoString;
  122.         
  123.         ::FW_PrivLoadUndoStrings(ev, FW_kUndoInsertMsg, undoString, redoString);
  124.         SetMenuStrings(ev, undoString, redoString);
  125.     }
  126.  
  127.     FW_END_CONSTRUCTOR
  128. }
  129.  
  130. //--------------------------------------------------------------------
  131. // FW_CInsertCommand destructor
  132. //--------------------------------------------------------------------
  133.  
  134. FW_CInsertCommand::~FW_CInsertCommand()
  135. {
  136.     FW_START_DESTRUCTOR
  137. }
  138.  
  139. //--------------------------------------------------------------------
  140. // FW_CInsertCommand::DoIt
  141. //--------------------------------------------------------------------
  142.  
  143. void FW_CInsertCommand::DoIt(Environment* ev)    // Override
  144. {
  145.     FW_Boolean result = FALSE;
  146.  
  147.     if (GetCanUndo(ev))
  148.         this->SaveUndoState(ev);    // save current state, for later Undo
  149.  
  150.     if (this->IsOKtoEdit(ev) && this->Insert(ev))
  151.     {
  152.         result = TRUE;
  153.     }
  154.  
  155.  
  156.     if (result == FALSE)
  157.     {
  158.         SetCanUndo(ev, FALSE);
  159.         SetCausesChange(ev, FALSE);
  160.     }
  161.     else if (GetCanUndo(ev))
  162.     {
  163.         this->SaveRedoState(ev);        // save new state, for later Redo
  164.     }
  165. }
  166.     
  167. //----------------------------------------------------------------------------------------
  168. //    FW_CInsertCommand::Insert
  169. //----------------------------------------------------------------------------------------
  170.  
  171. FW_Boolean FW_CInsertCommand::Insert(Environment* ev)
  172. {
  173.     PreCommand(ev);
  174.     
  175.     FW_Boolean result = FW_InsertPartFromFile(ev, fEmbeddingFrame, fFileSpec) != FW_kInternalizeFailed;
  176.     
  177.     if (result)
  178.         CommandDone(ev);
  179.         
  180.     return result;
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    FW_CInsertCommand::PreCommand
  185. //----------------------------------------------------------------------------------------
  186.  
  187. void FW_CInsertCommand::PreCommand(Environment* ev)
  188. {
  189. FW_UNUSED(ev);
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    FW_CInsertCommand::CommandDone
  194. //----------------------------------------------------------------------------------------
  195.  
  196. void FW_CInsertCommand::CommandDone(Environment* ev)
  197. {
  198. FW_UNUSED(ev);
  199.     // User may override; only gets called if the Insert was successful
  200. }
  201.  
  202.  
  203.  
  204.  
  205.